package o;

import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.hms.framework.network.restclient.hwhttp.trans.ByteString;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.util.Arrays;
import o.gcg.f;

final class gch {
    private static final char[] ʻ = new char[]{'\t', '\n', '\r', '\f', ' ', '<', '&'};
    static final int[] ॱ = new int[]{8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376};
    c ʼ = new c();
    b ʽ = new b();
    StringBuilder ˊ = new StringBuilder(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
    private gcg ˊॱ;
    j ˋ;
    private String ˋॱ = null;
    g ˎ = new g();
    i ˏ = new i();
    private final gca ˏॱ;
    private boolean ͺ = false;
    private gcf ॱˊ = gcf.Data;
    private StringBuilder ॱˋ = new StringBuilder(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
    private String ॱˎ;
    private final gbz ॱॱ;
    private final int[] ॱᐝ = new int[1];
    d ᐝ = new d();
    private final int[] ᐝॱ = new int[2];

    static {
        Arrays.sort(ʻ);
    }

    gch(gbz o_gbz, gca o_gca) {
        this.ॱॱ = o_gbz;
        this.ˏॱ = o_gca;
    }

    gcg ˎ() {
        while (!this.ͺ) {
            this.ॱˊ.ˏ(this, this.ॱॱ);
        }
        if (this.ॱˋ.length() > 0) {
            String stringBuilder = this.ॱˋ.toString();
            this.ॱˋ.delete(0, this.ॱˋ.length());
            this.ˋॱ = null;
            return this.ᐝ.getAttrName(stringBuilder);
        } else if (this.ˋॱ != null) {
            gcg ˊ = this.ᐝ.getAttrName(this.ˋॱ);
            this.ˋॱ = null;
            return ˊ;
        } else {
            this.ͺ = false;
            return this.ˊॱ;
        }
    }

    void ˎ(gcg o_gcg) {
        gbj.ˏ(this.ͺ, "There is an unread token pending!");
        this.ˊॱ = o_gcg;
        this.ͺ = true;
        if (o_gcg.ˎ == f.StartTag) {
            this.ॱˎ = ((i) o_gcg).attrValueRefId;
        } else if (o_gcg.ˎ == f.EndTag && ((g) o_gcg).attrValueRefName != null) {
            ˏ("Attributes incorrectly present on end tag");
        }
    }

    void ˊ(String str) {
        if (this.ˋॱ == null) {
            this.ˋॱ = str;
            return;
        }
        if (this.ॱˋ.length() == 0) {
            this.ॱˋ.append(this.ˋॱ);
        }
        this.ॱˋ.append(str);
    }

    void ॱ(int[] iArr) {
        ˊ(new String(iArr, 0, iArr.length));
    }

    void ˋ(char c) {
        ˊ(String.valueOf(c));
    }

    void ˎ(gcf o_gcf) {
        this.ॱˊ = o_gcf;
    }

    void ˏ(gcf o_gcf) {
        this.ॱॱ.ʽ();
        this.ॱˊ = o_gcf;
    }

    int[] ॱ(Character ch, boolean z) {
        if (this.ॱॱ.ˏ()) {
            return null;
        }
        if (ch != null && ch.charValue() == this.ॱॱ.ॱ()) {
            return null;
        }
        if (this.ॱॱ.ˊ(ʻ)) {
            return null;
        }
        int[] iArr = this.ॱᐝ;
        this.ॱॱ.ᐝ();
        int intValue;
        if (this.ॱॱ.ˋ("#")) {
            boolean ॱ = this.ॱॱ.ॱ("X");
            String ˏॱ = ॱ ? this.ॱॱ.ˏॱ() : this.ॱॱ.ͺ();
            if (ˏॱ.length() == 0) {
                ॱ("numeric reference with no numerals");
                this.ॱॱ.ʻ();
                return null;
            }
            if (!this.ॱॱ.ˋ(";")) {
                ॱ("missing semicolon");
            }
            try {
                intValue = Integer.valueOf(ˏॱ, ॱ ? 16 : 10).intValue();
            } catch (NumberFormatException e) {
                intValue = -1;
            }
            if (intValue == -1 || ((intValue >= 55296 && intValue <= 57343) || intValue > 1114111)) {
                ॱ("character outside of valid range");
                iArr[0] = ByteString.REPLACEMENT_CHARACTER;
                return iArr;
            }
            if (intValue >= DnsConfig.MAX_CACHE_ENTRIES && intValue < ॱ.length + DnsConfig.MAX_CACHE_ENTRIES) {
                ॱ("character is not a valid unicode code point");
                intValue = ॱ[intValue - 128];
            }
            iArr[0] = intValue;
            return iArr;
        }
        String ˋॱ = this.ॱॱ.ˋॱ();
        boolean ˏ = this.ॱॱ.ˏ(';');
        intValue = (gbt.ˎ(ˋॱ) || (gbt.ˋ(ˋॱ) && ˏ)) ? 1 : 0;
        if (intValue == 0) {
            this.ॱॱ.ʻ();
            if (ˏ) {
                ॱ(String.format("invalid named reference '%s'", new Object[]{ˋॱ}));
            }
            return null;
        } else if (z && (this.ॱॱ.ॱˎ() || this.ॱॱ.ᐝॱ() || this.ॱॱ.ˋ('=', '-', '_'))) {
            this.ॱॱ.ʻ();
            return null;
        } else {
            if (!this.ॱॱ.ˋ(";")) {
                ॱ("missing semicolon");
            }
            intValue = gbt.ˏ(ˋॱ, this.ᐝॱ);
            if (intValue == 1) {
                iArr[0] = this.ᐝॱ[0];
                return iArr;
            } else if (intValue == 2) {
                return this.ᐝॱ;
            } else {
                gbj.ˏ("Unexpected characters returned for " + ˋॱ);
                return this.ᐝॱ;
            }
        }
    }

    j ˊ(boolean z) {
        this.ˋ = z ? this.ˏ.ॱˊ() : this.ˎ.ॱˊ();
        return this.ˋ;
    }

    void ˊ() {
        this.ˋ.ʻॱ();
        ˎ(this.ˋ);
    }

    void ˋ() {
        this.ʽ.ˊ();
    }

    void ॱ() {
        ˎ(this.ʽ);
    }

    void ˏ() {
        this.ʼ.ˊ();
    }

    void ʽ() {
        ˎ(this.ʼ);
    }

    void ʼ() {
        gcg.ˏ(this.ˊ);
    }

    boolean ᐝ() {
        return this.ॱˎ != null && this.ˋ.ॱˎ().equalsIgnoreCase(this.ॱˎ);
    }

    String ʻ() {
        return this.ॱˎ;
    }

    void ˋ(gcf o_gcf) {
        if (this.ˏॱ.ˊ()) {
            this.ˏॱ.add(new gcc(this.ॱॱ.ˎ(), "Unexpected character '%s' in input state [%s]", Character.valueOf(this.ॱॱ.ॱ()), o_gcf));
        }
    }

    void ˊ(gcf o_gcf) {
        if (this.ˏॱ.ˊ()) {
            this.ˏॱ.add(new gcc(this.ॱॱ.ˎ(), "Unexpectedly reached end of file (EOF) in input state [%s]", o_gcf));
        }
    }

    private void ॱ(String str) {
        if (this.ˏॱ.ˊ()) {
            this.ˏॱ.add(new gcc(this.ॱॱ.ˎ(), "Invalid character reference: %s", str));
        }
    }

    void ˏ(String str) {
        if (this.ˏॱ.ˊ()) {
            this.ˏॱ.add(new gcc(this.ॱॱ.ˎ(), str));
        }
    }
}
